package com.cloud.netty.ProtocolTcp;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * @program: netty
 * @description:
 * @author: Cloud
 * @create: 2022/4/14 16:06:31
 */
public class ProMessageEncode extends MessageToByteEncoder<MessageProtocol> {


    @Override
    protected void encode(ChannelHandlerContext ctx, MessageProtocol msg, ByteBuf out) throws Exception {
        System.out.println();
        System.out.println("编码器被调用!");
        out.writeInt(msg.getLen());
        out.writeBytes(msg.getContent());
    }
}
